package com.szzg10.jsp.chapter9;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class AdvisorTagHandler extends SimpleTagSupport {

	private String user;
	
	@Override
	public void doTag() throws JspException, IOException {
		getJspContext().getOut().write("Hello " + user + " <br>");
		getJspContext().getOut().write("Your advice is: " + getAdvice());
	}
	
	String getAdvice() {
		String[] adviceStrings = {"That color's not working for you.",
			"You should call in sick.", "You might want to rethink that haircut."};
		
		int random = (int)(Math.random() * adviceStrings.length);
		
		return adviceStrings[random];
	}

	//---getter and setter---
	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}
}
